package pl.edu.agh.io.fx3.saver.generators;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import pl.edu.agh.io.fx3.utils.JDBCInfo;

public class SQLiteSchemaGenerator implements ISchemaGenerator {

	public void generate(JDBCInfo info) throws SQLException {
		try {
			Class.forName("org.sqlite.JDBC");
		} catch (ClassNotFoundException e) {
			throw new SQLException();
		}
		Connection conn = DriverManager.getConnection(info.getUrl());
		Statement stat = conn.createStatement();
		stat.executeUpdate("drop table if exists files;");
		stat.executeUpdate("CREATE TABLE files\n"
								+ "(\n"
								+ "id INTEGER PRIMARY KEY,\n"
								+ "virtual_path TEXT UNIQUE NOT NULL,\n"
								+ "real_path TEXT UNIQUE NOT NULL,\n"
								+ "checksum TEXT NOT NULL\n" + ");\n");

	}

}
